package com.jintoufs.service.banner.impl;

import com.jintoufs.dao.QueryFilters;
import com.jintoufs.dao.banner.BannerMapper;
import com.jintoufs.domain.banner.Banner;
import com.jintoufs.service.banner.BannerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by xufei on 2017/12/21.
 */
@Service
public class BannerServiceImpl implements BannerService {

    @Resource
    private BannerMapper bannerMapper;

    @Override
    public List<Map<String, Object>> queryByParams(Map<String, Object> params) {
        return bannerMapper.queryByParams(params);
    }

    @Override
    public Map<String, Object> save(Banner banner) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            if (banner.getId() == null || "".equals(banner.getId())) {
                banner.setDisplay(false);
                bannerMapper.insert(banner);
                result.put("msg", "新增成功");
            } else {
                bannerMapper.updateByPrimaryKeySelective(banner);
                result.put("msg", "更新成功");
            }
            result.put("status", "OK");
            return result;
        } catch (Exception e) {
            result.put("msg", "操作失败");
            result.put("status", "ERROR");
            return result;
        }
    }

    @Override
    public void delete(Integer id) {
        bannerMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Map<String,Object>> getByFilter(QueryFilters filters) {
        List<Map<String,Object>> result = bannerMapper.getByFilter(filters);
        return result;
    }

    @Override
    public Map<String,Object> getById(Integer id) {
        return bannerMapper.queryByPrimaryKey(id);
    }

    @Override
    public Banner selectById(Integer id){
        return bannerMapper.selectByPrimaryKey(id);
    }

}
